﻿using GetClient_info;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Vision.AlgBase.InspeAlg
{
    [ServiceData(SeriveName = "RGB识别", Descri = "啥也不检测")]
    public class TempRGBAlg : ToolBase
    {
        public enum ResultRGB
        {
            Green,//0,139,0
            DarkGreen,//深绿 0,94,0
            LightGreen//浅绿 0，221，0
        }
        /// <summary>
        /// 正确结果的颜色
        /// </summary>
        public ResultRGB IsOKResultRGB
        {
            get { return _isOKResultRGB; }
            set { _isOKResultRGB = value; }
        }
        ResultRGB _isOKResultRGB = ResultRGB.Green;

        /// <summary>
        /// 截取的原图
        /// </summary>
        public static Bitmap Image
        {
            get { return _image; }
            set { _image = value; }
        }
        static Bitmap _image = null;
        /// <summary>
        /// 预处理后的图像
        /// </summary>
        public static Bitmap Image2
        {
            get { return _image2; }
            set { _image2 = value; }
        }
        static Bitmap _image2 = null;

        protected override bool Excute()
        {
            //测试算法
            string str = GetIntPtr();
            if (str.Contains("OK"))
            {
                //根据句柄获取控件大小
                int x = 0, y = 0, wight = 0, hight = 0;
                OperationWindowProcess.GetWindowRect(ContorIntprt, ref x, ref y, ref wight, ref hight);
                //截图
                OperationWindowProcess.CaptureDesktop(x, y, wight, hight, out _image);
                int Rv = 0, Gv = 0, Bv = 0;
                switch (_isOKResultRGB)
                {
                    case ResultRGB.DarkGreen:
                        Rv = 0; Gv = 85; Bv = 0;
                        break;
                    case ResultRGB.Green:
                        Rv = 0; Gv = 150; Bv = 0;
                        break;
                    case ResultRGB.LightGreen:
                        Rv = 0; Gv = 211; Bv = 0;
                        break;


                }

                bool result = OperationWindowProcess.get_rgbstate(_image, Rv, Gv, Bv, 45, -45);
                ResultText = result ? "OK" : "NG";
                ErrLog = "";
                return true;

            }
            else
            {
                ErrLog = str;
                return false;

            }

        }
    }
}
